

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;


CREATE SCHEMA s_business;


COMMENT ON SCHEMA s_business IS 'Business Admin';


SET search_path = s_business, pg_catalog;

CREATE FUNCTION created_at_function() RETURNS trigger
LANGUAGE plpgsql
AS $$
declare
  t timestamptz;
BEGIN
  t := now();
  NEW.created_at = t;
  NEW.updated_at = t;
  RETURN NEW;
END;
$$;


CREATE FUNCTION updated_at_function() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
  NEW.updated_at = clock_timestamp();
  RETURN NEW;
END;
$$;


SET default_tablespace = '';

SET default_with_oids = false;


CREATE TABLE databasechangelog (
  id character varying(255) NOT NULL,
  author character varying(255) NOT NULL,
  filename character varying(255) NOT NULL,
  dateexecuted timestamp without time zone NOT NULL,
  orderexecuted integer NOT NULL,
  exectype character varying(10) NOT NULL,
  md5sum character varying(35),
  description character varying(255),
  comments character varying(255),
  tag character varying(255),
  liquibase character varying(20),
  contexts character varying(255),
  labels character varying(255),
  deployment_id character varying(10)
);



CREATE TABLE databasechangeloglock (
  id integer NOT NULL,
  locked boolean NOT NULL,
  lockgranted timestamp without time zone,
  lockedby character varying(255)
);


DROP TABLE IF EXISTS "s_business"."t_order";
CREATE TABLE "s_business"."t_order" (
  "id" BIGSERIAL NOT NULL,
  "order_no" varchar(64) COLLATE "pg_catalog"."default" NOT NULL,
  "subject" varchar(256) COLLATE "pg_catalog"."default" NOT NULL,
  "detail" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "total_amount" int8 NOT NULL,
  "goods_category" int2 NOT NULL,
  "trade_no" varchar(64) COLLATE "pg_catalog"."default",
  "channel" int2 NOT NULL,
  "goods_id" int8 NOT NULL,
  "discount_id" int8 NOT NULL,
  "buyer_id" int8 NOT NULL,
  "open_id" text NOT NULL,
  "status" int2 NOT NULL,
  "created_at" timestamp(0) NOT NULL,
  "updated_at" timestamp(0) NOT NULL,
  "deleted_at" timestamp(0),
  "invalid_at" timestamp(0) NOT NULL,
  "pay_at" timestamp(0)
)
;
COMMENT ON COLUMN "s_business"."t_order"."order_no" IS '订单号';
COMMENT ON COLUMN "s_business"."t_order"."subject" IS '主题';
COMMENT ON COLUMN "s_business"."t_order"."detail" IS '描述';
COMMENT ON COLUMN "s_business"."t_order"."total_amount" IS '商品总额';
COMMENT ON COLUMN "s_business"."t_order"."goods_category" IS '商品类型';
COMMENT ON COLUMN "s_business"."t_order"."trade_no" IS '第三方流水号';
COMMENT ON COLUMN "s_business"."t_order"."channel" IS '支付渠道';
COMMENT ON COLUMN "s_business"."t_order"."goods_id" IS '商品id';
COMMENT ON COLUMN "s_business"."t_order"."buyer_id" IS '买家id';
COMMENT ON COLUMN "s_business"."t_order"."status" IS '订单状态';
COMMENT ON COLUMN "s_business"."t_order"."invalid_at" IS '订单失效时间';
COMMENT ON COLUMN "s_business"."t_order"."pay_at" IS '支付时间';


-- ----------------------------
-- Triggers structure for table t_order
-- ----------------------------
CREATE TRIGGER "created_at_t_order_trigger" BEFORE INSERT ON "s_business"."t_order"
  FOR EACH ROW
EXECUTE PROCEDURE "s_business"."created_at_function"();
CREATE TRIGGER "updated_at_t_order_trigger" BEFORE UPDATE ON "s_business"."t_order"
  FOR EACH ROW
EXECUTE PROCEDURE "s_business"."updated_at_function"();

-- ----------------------------
-- Primary Key structure for table t_order
-- ----------------------------
ALTER TABLE "s_business"."t_order" ADD CONSTRAINT "t_order_pkey" PRIMARY KEY ("id");




DROP TABLE IF EXISTS "s_business"."t_bought_record";
CREATE TABLE "s_business"."t_bought_record" (
  "id" int8 NOT NULL DEFAULT 1,
  "buyer_id" int8 NOT NULL,
  "category" int2 NOT NULL,
  "deal_at" timestamp(0),
  "order_id" int8 NOT NULL,
  "exam_id" int8 NOT NULL,
  "created_at" timestamp(0) NOT NULL,
  "updated_at" timestamp(0) NOT NULL,
  "deleted_at" timestamp(0),
  "count" int8 NOT NULL DEFAULT 1
)
;
ALTER TABLE "s_business"."t_bought_record" OWNER TO "postgres";
COMMENT ON COLUMN "s_business"."t_bought_record"."buyer_id" IS '买家id';
COMMENT ON COLUMN "s_business"."t_bought_record"."category" IS '商品类型';
COMMENT ON COLUMN "s_business"."t_bought_record"."deal_at" IS '成交时间';
COMMENT ON COLUMN "s_business"."t_bought_record"."order_id" IS '订单id';
COMMENT ON COLUMN "s_business"."t_bought_record"."count" IS '商品数量';

-- ----------------------------
-- Triggers structure for table t_bought_record
-- ----------------------------
CREATE TRIGGER "created_at_t_bought_record_trigger" BEFORE INSERT ON "s_business"."t_bought_record"
  FOR EACH ROW
EXECUTE PROCEDURE "s_business"."created_at_function"();
CREATE TRIGGER "updated_at_t_bought_record_trigger" BEFORE UPDATE ON "s_business"."t_bought_record"
  FOR EACH ROW
EXECUTE PROCEDURE "s_business"."updated_at_function"();

-- ----------------------------
-- Primary Key structure for table t_bought_record
-- ----------------------------
ALTER TABLE "s_business"."t_bought_record" ADD CONSTRAINT "t_bought_record_pkey" PRIMARY KEY ("id");



